using System;
using System.Collections.Generic;
using System.Text;
using Lincolnwood.Foundation.Common.Data;
using Lincolnwood.Foundation.SermonLibrary;
using Iesi.Collections.Generic;

namespace Lincolnwood.Foundation.SermonLibrary
{
    [Serializable]
    public class Sermon : AuditableEntity<Guid>
    {
        private string _title;
        private string _description;
        private Speaker _speaker;
        private DateTime _recordedDate;
        private string _recordedAtLocation;
        private bool _isPublished;
        private MediaLink _media;
        private Iesi.Collections.Generic.ISet<ScriptureReference> _scriptureReferences = new Iesi.Collections.Generic.SortedSet<ScriptureReference>();
        private SermonSeries _series;

        public Sermon()
        {
        }

        public Sermon(string title, string description, string speakerFirstName, 
            string speakerLastName, string speakerTitle, DateTime recordedDate, string recordedAtLocation, MediaLink mediaLink) : this()
        {
            _title = title;
            _description = description;
            _recordedDate = recordedDate;
            _recordedAtLocation = recordedAtLocation;
            _speaker = new Speaker(speakerFirstName, speakerLastName, speakerTitle);
            _media = mediaLink;
        }

        /// <summary>
        /// The title or name of the sermon.
        /// </summary>
        public string Title
        {
            get { return _title; }
            set { _title = value; }
        }

        /// <summary>
        /// Brief summary or description of the sermon's contents or message.
        /// </summary>
        public string Description
        {
            get { return _description; }
            set { _description = value; }
        }

        /// <summary>
        /// The speaker who delivered the sermon.
        /// </summary>
        public Speaker Speaker
        {
            get { return _speaker; }
            set { _speaker = value; }
        }

        /// <summary>
        /// The name of place that the sermon was preached.
        /// </summary>
        public string RecordedAtLocation
        {
            get { return _recordedAtLocation; }
            set { _recordedAtLocation = value; }
        }

        /// <summary>
        /// The date that the sermon was recorded.
        /// </summary>
        public DateTime RecordedDate
        {
            get { return _recordedDate; }
            set { _recordedDate = value; }
        }

        /// <summary>
        /// The date that the sermon was published
        /// </summary>
        public bool IsPublished
        {
            get { return _isPublished; }
            set { _isPublished = value; }
        }
        
        /// <summary>
        /// The media (Audio or Video) that was recorded of this sermon (if any)
        /// </summary>
        public MediaLink Media
        {
            get { return _media; }
            set { _media = value; }
        }


        public SermonSeries Series
        {
            get { return _series; }
            set { _series = value; }
        }

        /// <summary>
        /// A set of scriptural references used in this sermon.
        /// </summary>
        public Iesi.Collections.Generic.ISet<ScriptureReference> ScriptureReferences
        {
            get { return _scriptureReferences; }
        }

        public override bool Equals(object obj)
        {
            var testSermon = obj as Sermon;
            if (testSermon == null)
                return false;
            else
                return Equals(testSermon);
        }

        private bool Equals(Sermon arg)
        {
            if (this == arg)
                return true;

            var scriptureReferencesComparer = new CollectionComparer<ScriptureReference>();

            return
            Title.Equals(arg.Title) &&
            Description.Equals(arg.Description) &&
            RecordedDate.Equals(arg.RecordedDate) &&
            RecordedAtLocation.Equals(arg.RecordedAtLocation) &&
            Media.Equals(arg.Media) &&
            IsPublished.Equals(arg.IsPublished) &&
            Speaker.Equals(arg.Speaker) &&           
            scriptureReferencesComparer.Equals(ScriptureReferences, arg.ScriptureReferences);
        }

    }
}